//SPDX-FileCopyrightText: Copyright 2025-2025 深圳市同心圆网络有限公司
//SPDX-License-Identifier: GPL-3.0-only

use proto_gen_rust::ai_provider_api::ai_provider_api_client::AiProviderApiClient;
use proto_gen_rust::ai_provider_api::*;
use tauri::{AppHandle, Runtime};


#[tauri::command]
pub async fn ai_provider_api_cmds_list_llm_provider<R: Runtime>(
    app_handle: AppHandle<R>,
    request: ListLlmProviderRequest,
) -> Result<ListLlmProviderResponse, String> {
    let chan = crate::get_grpc_chan(&app_handle).await;
    if (&chan).is_none() {
        return Err("no grpc conn".into());
    }
    let mut client = AiProviderApiClient::new(chan.unwrap());
    match client.list_llm_provider(request).await {
        Ok(response) => {
            let inner_resp = response.into_inner();
            return Ok(inner_resp);
        }
        Err(status) => Err(status.message().into()),
    }
}